package com.kaoshi.myweb.snippet.mq.rabbitmq.publish;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Administrator on 2017/3/4.
 */
public class HelloWorld {

	static String queuename = "hello";

	public static void main(String[] args) throws IOException, TimeoutException {
		ConnectionFactory factory = new ConnectionFactory();
		factory.setHost("localhost");
		Connection connection = factory.newConnection();
		Channel channel = connection.createChannel();
		channel.queueDeclare(queuename, false, false, false, null);
		String msg = "hello world（consumer-->HelleWorldRecv）";
		channel.basicPublish("", queuename, null, msg.getBytes());
		System.out.println(" [x] Sent '" + msg + "'");
		channel.close();
		connection.close();
	}
}
